vm.attributes["actions_after_reboot"].value,
"actions_after_crash":
vm.attributes["actions_after_crash"].value,
- "platform_std_VGA":
- vm.attributes["platform_std_VGA"].value,
- "platform_serial":
- vm.attributes["platform_serial"].value,
- "platform_localtime":
- vm.attributes["platform_localtime"].value,
- "platform_clock_offet":
- vm.attributes["platform_clock_offet"].value,
- "platform_enable_audio":
- vm.attributes["platform_enable_audio"].value,
- "PCI_bus":
- vm.attributes["platform_enable_audio"].value,
+ "platform":
+ get_child_nodes_as_dict(vm, "platform", "key", "value"),
"other_config":
get_child_nodes_as_dict(vm, "other_config", "key", "value")
}
"HVM_boot_policy":
get_child_node_attribute(vm, "hvm", "boot_policy"),
"HVM_boot_params":
- get_child_nodes_as_dict(hvm, "boot_params", "key", "value")
+ get_child_nodes_as_dict(hvm, "boot_param", "key", "value")
})
try:
vm_ref = server.xenapi.VM.create(vm_record)
self.create_vifs(vm_ref, vifs)
+ # Now create consoles
+
+ consoles = vm.getElementsByTagName("console")
+
+ self.create_consoles(vm_ref, consoles)
+
return vm_ref
except:
server.xenapi.VM.destroy(vm_ref)
self._network_refs = server.xenapi.network.get_all()
return self._network_refs.pop(0)
+ def create_consoles(self, vm_ref, consoles):
+ log(DEBUG, "create_consoles")
+ return map(lambda console: self.create_console(vm_ref, console),
+ consoles)
+
+ def create_console(self, vm_ref, console):
+ log(DEBUG, "create_consoles")
+
+ console_record = {
+ "VM":
+ vm_ref,
+ "protocol":
+ console.attributes["protocol"].value,
+ "other_params":
+ get_child_nodes_as_dict(console,
+ "other_param", "key", "value")
+ }
+
+ return server.xenapi.console.create(console_record)
+
def get_child_by_name(exp, childname, default = None):
try:
return [child for child in sxp.children(exp)
= actions_after_reboot
vm.attributes["actions_after_crash"] \
= actions_after_crash
- vm.attributes["platform_std_VGA"] = "false"
- vm.attributes["platform_serial"] = ""
- vm.attributes["platform_localtime"] = ""
- vm.attributes["platform_clock_offet"] = ""
- vm.attributes["platform_enable_audio"] = ""
vm.attributes["PCI_bus"] = ""
vm.attributes["vcpus_max"] \
vm.appendChild(pv)
elif image[0] == "hvm":
hvm = document.createElement("hvm")
- hvm.attributes["boot_policy"] = ""
+ hvm.attributes["boot_policy"] = "BIOS order"
+
+ boot_order = document.createElement("boot_param")
+ boot_order.attributes["key"] = "order"
+ boot_order.attributes["value"] \
+ = get_child_by_name(image, "boot", "abcd")
+ hvm.appendChild
vm.appendChild(hvm)
map(vm.appendChild, vifs)
+ # Last but not least the consoles...
+
+ consoles = self.extract_consoles(image, document)
+
+ map(vm.appendChild, consoles)
+
+ # Platform variables...
+
+ platform = self.extract_platform(image, document)
+
+ map(vm.appendChild, platform)
+
# transient?
if transient:
_eths = -1
+ def mk_other_config(self, key, value, document):
+ other_config = document.createElement("other_config")
+ other_config.attributes["key"] = key
+ other_config.attributes["value"] = value
+ return other_config
+
+ def extract_consoles(self, image, document):
+ consoles = []
+
+ if int(get_child_by_name(image, "nographic", "1")) == 1:
+ return consoles
+
+ if int(get_child_by_name(image, "vnc", "0")) == 1:
+ console = document.createElement("console")
+ console.attributes["protocol"] = "rfb"
+ console.appendChild(self.mk_other_config(
+ "vncunused", str(get_child_by_name(image, "vncunused", "0")),
+ document))
+ console.appendChild(self.mk_other_config(
+ "vnclisten",
+ get_child_by_name(image, "vnclisten", "127.0.0.1"),
+ document))
+ console.appendChild(self.mk_other_config(
+ "vncpasswd", get_child_by_name(image, "vncpasswd", ""),
+ document))
+ consoles.append(console)
+ if int(get_child_by_name(image, "sdl", "0")) == 1:
+ console = document.createElement("console")
+ console.attributes["protocol"] = "sdl"
+ console.appendChild(self.mk_other_config(
+ "display", get_child_by_name(image, "display", ""),
+ document))
+ console.appendChild(self.mk_other_config(
+ "xauthority",
+ get_child_by_name(image, "vxauthority", "127.0.0.1"),
+ document))
+ console.appendChild(self.mk_other_config(
+ "vncpasswd", get_child_by_name(image, "vncpasswd", ""),
+ document))
+ consoles.append(console)
+
+ return consoles
+
+
+ def extract_platform(self, image, document):
+ platform_keys = ['acpi', 'apic', 'pae']
+
+ def extract_platform_key(key):
+ platform = document.createElement("platform")
+ platform.attributes["key"] = key
+ platform.attributes["value"] \
+ = str(get_child_by_name(image, key, "1"))
+ return platform
+
+ return map(extract_platform_key, platform_keys)
+
def getFreshEthDevice(self):
self._eths += 1
return "eth%i" % self._eths